<?php
namespace app\addons\controller;
// use app\index\
class General extends Base
{
    public function index()
    {

        // print_r($cid);
        $article=db("plugin_general");
        $keywords=request()->param('keywords');

        $where['status']=1;


        if($keywords){
            $where['title']=['like', '%'.$keywords.'%'];
        }

        $count=$article->where($where)->count();
        $data=$article->where($where)->order("sort asc,id desc")->select();


        $this->assign("cid",$cid);
        $this->assign("mess",$data);
        $this->assign("count",$count);
        return view('index');
    }
    public function index_del(){
        $id=$_GET['id'];
        $res=db("plugin_general")->delete($id);
        if($res){
            $mess['code']=1;
            $mess['msg']="删除成功";
        }else{
            $mess['code']=0;
            $mess['msg']="删除失败";
        }       // print_r($data);exit;
        return json_encode($mess);
    }
    public function addArticle()
    {
        $id=request()->param('id');
        if($id){
            $mess=db("plugin_general")->where("id",$id)->find();
            $this->assign("mess",$mess);
        }        

        return view('addArticle');
    }
    public function aboutAddDone()
    {
        $updid=request()->param('updid'); 
        $data=$_POST;
        $data['aid']=$this->userMsg['id'];
        if($updid){
            $res=db("plugin_general")->where("id",$updid)->update($data);
        }else{
            $res=db("plugin_general")->insert($data);
        }
        if($res){
            $mess['code']=200;
            $mess['msg']='保存成功';
        }else{
            $mess['code']=100;
            $mess['msg']='保存失败';
        }        
        return json_encode($mess);
    }    
    public function cateSort(){
        $id=request()->param('id');            
        $sort=request()->param('sort');

        $data['sort']=$sort;
        $res=db("plugin_general")->where("id",$id)->update($data);
        if($res){
            $mess['code']=1;
            $mess['msg']="操作成功";
        }else{
            $mess['code']=0;
            $mess['msg']="操作失败";
        }
        return json_encode($mess);   
    }
}
